package com.example.lxj.LegalCase.controller;

import java.util.List;
import java.util.Optional;

import com.example.lxj.base.annoation.Permission;
import com.example.lxj.base.controller.BaseController;
import com.example.lxj.base.entity.AjaxRes;
import com.example.lxj.base.entity.PageDTO;
import com.example.lxj.base.entity.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.lxj.LegalCase.entity.TbCaseIdentificationMaterials;
import com.example.lxj.LegalCase.service.ITbCaseIdentificationMaterialsService;

import static com.github.pagehelper.page.PageMethod.startPage;

/**
 * 案件鉴定材料Controller
 *
 * @author lxj
 * @date 2024-10-23
 */
@RestController
@RequestMapping("/LegalCase/case_identifications_materials")
public class TbCaseIdentificationMaterialsController extends BaseController {
    @Autowired
    private ITbCaseIdentificationMaterialsService tbCaseIdentificationMaterialsService;

    /**
     * 查询案件鉴定材料列表
     */
    @Permission(value = "LegalCase:case_identifications_materials:list")
    @GetMapping("/list")
    public TableDataInfo list(TbCaseIdentificationMaterials tbCaseIdentificationMaterials, PageDTO pageDTO) {
        startPage(Optional.ofNullable(pageDTO.getPageNo()).orElse(1), Optional.ofNullable(pageDTO.getPageSize()).orElse(10));
        List<TbCaseIdentificationMaterials> list = tbCaseIdentificationMaterialsService.selectTbCaseIdentificationMaterialsList(tbCaseIdentificationMaterials);
        return getDataTable(list);
    }

    /**
     * 获取案件鉴定材料详细信息
     */
    @Permission(value = "LegalCase:case_identifications_materials:query")
    @GetMapping(value = "/{id}")
    public AjaxRes getInfo(@PathVariable("id") Long id) {
        return success(tbCaseIdentificationMaterialsService.selectTbCaseIdentificationMaterialsById(id));
    }

    /**
     * 新增案件鉴定材料
     */
    @Permission(value = "LegalCase:case_identifications_materials:add")
    @PostMapping
    public AjaxRes add(@RequestBody TbCaseIdentificationMaterials tbCaseIdentificationMaterials) {
        return toAjax(tbCaseIdentificationMaterialsService.insertTbCaseIdentificationMaterials(tbCaseIdentificationMaterials));
    }

    /**
     * 修改案件鉴定材料
     */
    @Permission(value = "LegalCase:case_identifications_materials:edit")
    @PutMapping
    public AjaxRes edit(@RequestBody TbCaseIdentificationMaterials tbCaseIdentificationMaterials) {
        return toAjax(tbCaseIdentificationMaterialsService.updateTbCaseIdentificationMaterials(tbCaseIdentificationMaterials));
    }

    /**
     * 删除案件鉴定材料
     */
    @Permission(value = "LegalCase:case_identifications_materials:remove")
    @DeleteMapping("/{ids}")
    public AjaxRes remove(@PathVariable("ids") Long[] ids) {
        return toAjax(tbCaseIdentificationMaterialsService.deleteTbCaseIdentificationMaterialsByIds(ids));
    }
}
